﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using H2.NET.Business;

namespace H2.NET.Web.Controls
{
    public partial class ControlsAssessment : TaskControl
    {
        public bool Enable = true;
        public List<t_AssessmentOption> Option = new List<t_AssessmentOption>();

        #region 事件 Load (页面)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //重转“选择项”
                int Selected = 0;
                RadOpition.Items.Clear();

                for (int i = 0; i < Option.Count;i++ )
                {
                    RadOpition.Items.Add(new ListItem(Option[i].RadName, Option[i].RadValue));

                    //取得默认值
                    if (Option[i].IsDefault)
                    {
                        Selected = i;
                    }
                }

                //初始化“选择项”选择、备注框对应值
                if (Option.Count > 0)
                {
                    RadOpition.Items[Selected].Selected = true;
                }

                //设置是否只读
                StepLabel.Text = TaskAPI.Step + ":";
                RadOpition.Enabled = Enable;
                Remark.Enabled     = Enable;
            }
        }
        #endregion

        #region 方法 提取 Assessment
        /// <summary>
        /// 
        /// </summary>
        /// <param name="User"></param>
        /// <param name="Task"></param>
        public t_Assessment Assessment
        {
            get
            {
                t_Assessment ass   = new t_Assessment();
                ass.Process      = TaskAPI.Process;
                ass.Incident     = TaskAPI.Incident;
                ass.Step         = TaskAPI.Step;
                ass.UserName     = TaskAPI.UserName;
                ass.UserFullName = TaskAPI.UserFullName;
                ass.AssignedToUserName     = UserAPI.UserName;
                ass.AssignedToUserFullName = UserAPI.UserFullName;
                ass.Department   = UserAPI.Department;
                ass.StartTime    = TaskAPI.StartTime;
                ass.Time         = System.DateTime.Now;
                ass.Opinion      = RadOpition.SelectedValue;
                ass.OpinionText  = RadOpition.SelectedItem == null ? "" : RadOpition.SelectedItem.Text;
                ass.Opinion2     = "";
                ass.OpinionText2 = "";
                ass.Status       = 1;
                foreach(ListItem li in RadOpition.Items)
                {
                    ass.Opinion2     += li.Value + "~";
                    ass.OpinionText2 += li.Text + "~";
                }
                ass.Remark       = Remark.Text;

                return ass;
            }
        }
        #endregion
    }
}
